<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2024/5/22
  Time: 16:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生信息更新</title>
</head>
<body>
<div class="container">
    <jsp:include page="../../top.jsp"/>
    <div id="cont"class="row">
        <section class="col-sm-8 offset-sm-2">
            <form novalidate id="updateForm" method="post">
                <!--第一行-->
                <div class="form-row">
                  <div class="form-group col-md-6">
                    <label>系统标识：</label>
                    <input type="text" class="form-control" name="id" value="${requestScope.studentToUpdate.id}" readonly />
                  </div>
                  <div class="form-group col-md-6">
                    <label>学号：</label>
                    <input type="text" class="form-control" name="no" value="${requestScope.studentToUpdate.no}" required/>
                    <div class="invalid-feedback">学号不能为空</div>
                  </div>
                </div>

                <!--第二行-->
                <div class="form-row">
                  <div class="form-group col-md-6">
                    <label>姓名：</label>
                    <input type="text" class="form-control" name="realName" value="${requestScope.studentToUpdate.realName}" required />
                    <div class="invalid-feedback">姓名不能为空</div>
                  </div>
                  <div class="form-group col-md-6">
                    <label>生日：</label>
                    <input type="text" class="form-control" name="birthDay" id="birthDay" readonly required value="${requestScope.studentToUpdate.birthDay}"/>
                    <div class="invalid-feedback">生日不能为空</div>
                  </div>
                </div>

                <!--第三行-->
                <div class="form-row">
                  <div class="form-group col-md-6">
                    <label>手机：</label>
                    <input type="text" class="form-control" name="phone" autocomplete="off" required value="${requestScope.studentToUpdate.phone}"/>
                    <div class="invalid-feedback">手机不能为空</div>
                  </div>
                  <div class="form-group col-md-6">
                    <label>邮箱：</label>
                    <input type="email" class="form-control" name="email" required value="${requestScope.studentToUpdate.email}"/>
                    <div class="invalid-feedback">请输入符合格式的邮箱</div>
                  </div>
                </div>
                <div class="form-group">
                  <label c1ass="d-block">免冠照：</label>
                  <div class="img-show">
                    <img class="img-fluid" src="${requestScope.studentToUpdate.addressablePhotoPath}"/>
                  </div>
                </div>
                <div class="d-flex justify-content-around">
                  <input type="button" id="modify" class="btn btn-primary" value="修改"/>
                  <a class="btn btn-primary" href="#" onclick="history.go(-1)">返回</a>
                </div>
            </form>
        </section>
    </div>
    <script>
        $("#modify").on("click",function () {
            var validateResult = document.getElementById("updateForm").checkValidity();
            $("#updateForm").addClass("was-validated");
            if (!validateResult) {
                return;
            }
            $.ajax({
                type:'post',
                url:"<%=request.getContextPath()%>/admin/updateStudent",
                data:formDataObj("#updateForm"),
                success:function (result) {
                    if (result.success) {
                        location.href ='<%=request.getContextPath()%>/admin/toStudentManage?pageNow=${requestScope.pageNow}'
                    } else {
                        $("#tipCont").text(result.errMsg);
                        $("#tipModal").modal("show");
                    }
                }
            });
        })
    </script>
</body>
</html>
